@extends('layouts.admin')

@section('title', '树种分类')

@section('content')
    <div class="console-title">
        <h2>游戏设置>树种分类</h2>
    </div>
    <div class="content-div">
        <form method="post" autocomplete="off" id="listForm">
            {{form_verify_field()}}
            <table width="100%" border="0" cellspacing="0" cellpadding="0" class="listtable">
                <thead>
                <tr>
                    <th width="50" class="center">删?</th>
                    <th width="50">图片</th>
                    <th>树种名称</th>
                    <th>所需积分</th>
                    <th>气泡数</th>
                    <th>释放天数</th>
                </tr>
                </thead>
                <tbody id="types">
                @foreach($items as $item)
                    <tr>
                        <td><input title="" type="checkbox" class="checkmark" name="delete[]" value="{{$item['treeid']}}"></td>
                        <td><img src="{{image_url($item['image'])}}" width="30" height="30" rel="pickimg" data-id="{{$item['treeid']}}"></td>
                        <td><input title="" type="text" class="form-control w200" name="trees[{{$item['treeid']}}][title]" value="{{$item['title']}}"></td>
                        <td><input title="" type="text" class="form-control w100" name="trees[{{$item['treeid']}}][points]" value="{{$item['points']}}"></td>
                        <td><input title="" type="text" class="form-control w100" name="trees[{{$item['treeid']}}][bubbles]" value="{{$item['bubbles']}}"></td>
                        <td><input title="" type="text" class="form-control w100" name="trees[{{$item['treeid']}}][days]" value="{{$item['days']}}"></td>
                    </tr>
                @endforeach
                </tbody>
                <tfoot>
                <tr>
                    <td colspan="10">
                        <label><input type="checkbox" data-action="checkall"> {{trans('common.selectall')}}</label>
                        <a id="addnew"><i class="iconfont icon-roundaddfill"></i>添加树种</a>
                    </td>
                </tr>
                <tr>
                    <td colspan="10">
                        <div class="btn-group-sm">
                            <label><input type="button" class="btn btn-primary" value="{{trans('common.submit')}}" id="submitButton"></label>
                            <label><input type="button" class="btn btn-default" value="{{trans('common.refresh')}}" data-action="refresh"></label>
                        </div>
                    </td>
                </tr>
                </tfoot>
            </table>
        </form>
    </div>
@stop

@section('foot')
    <script type="text/javascript">
        var typeid = 0;
        $("#addnew").on('click', function () {
            $("#types").append('<tr>' +
                '                <td></td>' +
                '                <td></td>' +
                '                <td><input type="text" class="form-control w200" name="trees['+typeid+'][title]"></td>\n' +
                '                <td><input type="text" class="form-control w100" name="trees['+typeid+'][points]"></td>\n' +
                '                <td><input type="text" class="form-control w100" name="trees['+typeid+'][bubbles]"></td>\n' +
                '                <td><input type="text" class="form-control w100" name="trees['+typeid+'][days]"></td>\n' +
                '            </tr>');
            typeid--;
        });
        $("#submitButton").on('click', function () {
            if ($(".checkmark:checked").length > 0) {
                DSXUI.showConfirm('你确认要删除所选项目吗?', function () {
                    $("#listForm").submit();
                });
            } else {
                $("#listForm").submit();
            }
        });
        $("[rel=pickimg]").on('click', function () {
            var $this = $(this);
            var treeid = $this.attr('data-id');
            Plugins.showImagePicker(function (data) {
                $this.attr('src', data.imageurl);
                $.ajax({
                    type:'POST',
                    url:'{{admin_url('game/settreeimg')}}',
                    data:{treeid:treeid,image:data.image},
                });
            });
        });
    </script>
@stop
